package it.polimi.travelDreamEJB.web.beans;

import java.util.List;

import it.polimi.travelDreamEJB.basicproductmanagement.BasicProductMgr;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.HotelDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.SearchHotelDTO;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import org.primefaces.event.RowEditEvent;

import javax.faces.context.FacesContext;  

@ManagedBean(name = "hotelBean")
@ViewScoped
public class HotelBean{

	@EJB
	private BasicProductMgr bpm;

	private HotelDTO hotel;

	private SearchHotelDTO searchHotel;

	private List<HotelDTO> hotelList;

	public HotelBean() {
		searchHotel = new SearchHotelDTO();
		hotel = new HotelDTO();
		hotel.setStars(1);
	}

	public HotelDTO getHotel() {
		return hotel;
	}

	public void setHotel(HotelDTO hotel) {
		this.hotel = hotel;
	}

	public String save() {
		bpm.save_hotel(hotel);
		return "basic?faces-redirect=true";
	}

	public SearchHotelDTO getSearchHotel() {
		return searchHotel;
	}
	
	public void setSearchHotel(SearchHotelDTO searchHotel) {
		this.searchHotel = searchHotel;
	}

	public List<HotelDTO> getHotelList() {
		return hotelList;
	}

	public void setHotelList(List<HotelDTO> hotelList) {
		this.hotelList = hotelList;
	}

	public void find() {

		hotelList = bpm.findHotel(searchHotel);

	}

	public void delete(RowEditEvent event) {

		hotel = ((HotelDTO) event.getObject());
		bpm.delete_hotel(hotel);
		hotelList.remove(hotel);

	}

	public void update(RowEditEvent event) {

		bpm.update_hotel(((HotelDTO) event.getObject()));

	}

}
